{layout name="public/layout" /}
{include file='yxnavbar'}


<div class="main">
    {include file='koi_common_nav'}
    <div class="panel panel-default" role="tabpanel">
        <div class="panel-heading">基本信息</div>
        <div class="panel-body">
            <form action="" method="post" class="form-horizontal" role="form" name="form2" id="form2">
                <input type="hidden" name="l_id" value="{$item['l_id']}"/>
                <input type="hidden" name="themeid" value="{$themeid}"/>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>锦鲤名称</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="text" class="form-control"  id="title" placeholder="" name="title"  value="{$item['title']}">
                        <span class="help-block">示例：金锦鲤 玉锦鲤 </span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">锦鲤类型</label>
                    <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
                        <label class="radio-inline">
                            <input name="in_prize" value="2" {if $item['in_prize']==2 || !$item['in_prize']} checked="checked"{/if} type="radio"> 抽奖锦鲤
                        </label>
                        <label class="radio-inline">
                            <input name="in_prize" value="1" {if $item['in_prize']==1} checked="checked"{/if} type="radio">兑换锦鲤
                        </label>
                        <span class="help-block">如：属于兑换锦鲤将不在抽奖奖项中展现，抽奖锦鲤数最大为5个</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">最大兑换锦鲤</label>
                    <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
                        <label class="radio-inline">
                            <input name="is_max" value="2" {if $item['is_max']==2 || !$item['is_max']} checked="checked"{/if} type="radio"> 否
                        </label>
                        <label class="radio-inline">
                            <input name="is_max" value="1" {if $item['is_max']==1} checked="checked"{/if} type="radio">是
                        </label>
                        <span class="help-block">如：属于兑换锦鲤将不在抽奖奖项中展现</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>锦鲤小图</label>
                    <div class="col-sm-8 col-xs-12">
                        {php echo view_form_field_image('img',$item['img']);}
                        <span class="help-block">图片尺寸：200*200像素</span>
                    </div>
                </div>

                <div class="form-group" id="sub_upload" >
                    <div class="col-sm-12">
                        <input name="submit" onclick="addOrEditLtItem()" id="btnConfirm" type="button" value="提交" class="btn btn-primary col-lg-2">
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(
        function (){
        }
    );
    function drop_confirm(msg, url){
        if(confirm(msg)){
            window.location = url;
        }
    }
    //新增\修改 提交数据
    function addOrEditLtItem() {
        if ($("#title").val().length==0){
            layer.msg('请输入锦鲤名称');
            return;
        }
        let postUrl = "{php echo createWebUrl('koi',array('op'=>'list_update'));}";
        let success_redirect = "{php echo createWebUrl('koi',array('op'=>'list'));}";
        let formData = $("#form2").serialize();
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:formData,
            success:function (e) {
                let res = e.message;
                let code = res.code;
                let msg = res.msg;
                if (code!=200){
                    layer.msg(msg)
                }else{
                    layer.msg(msg);
                    window.location.href = success_redirect;
                }

            },
            fail:function (err) {
                console.log(err)
            }
        })
    }
    // 修改、删除奖品
    function changeOrDelLttInfo(e) {
        let ltt_id = e.getAttribute("data-id");
        let type = e.getAttribute("data-type");
        let themeid = e.getAttribute("data-themeid");
        let redirectUrl = e.getAttribute("data-edit-url");
        let postUrl ="";
        if (type=='edit'){
            window.location.href = redirectUrl;
        }
        if (type=='del'){
            postUrl = "{php echo createWebUrl('lt_delltitem');}";
            layer.msg('您确定删除该奖品吗？',{
                btn:['确定','取消'],
                yes:function (index) {
                    $.ajax({
                        url:postUrl,
                        dataType:'json',
                        method:'post',
                        data: {ltt_id:ltt_id,themeid:themeid},
                        success:function (e) {
                            let res = e.message;
                            let code = res.code;
                            let msg = res.msg;
                            if (code!=200){
                                layer.msg(msg);
                            }else{
                                layer.msg(msg);
                                location.reload();
                            }
                        },
                        fail:function (err) {
                            console.log(err)
                        }
                    });
                }
            });
        }
    }
</script>
